<?php

namespace api\controllers;


use api\components\BaseController;
use common\helpers\commonApi;
use common\helpers\TransformApi;
use common\models\Vip;
use common\models\VipLog;
use Yii;

/**
 * vip
 * Class VipController
 * @package api\controllers
 */
class VipController extends BaseController
{
    /**
     * 列表
     * @return array
     */
    public function actionList()
    {
        $data = Vip::find()
            ->select(['id as v_ip','days','amount','title'])
            ->where(['status'=>1])
            ->orderBy(['sort'=>SORT_DESC,'create_time'=>SORT_DESC])
            ->asArray()->all();
        foreach ($data as &$datum){
            $one_day_price = $datum['amount']/$datum['days'];
            $one_day_price = TransformApi::DecimalPoint($one_day_price,2);
            $datum['one_day_price'] = $one_day_price;
        }
        return commonApi::message('获取成功',true,$data);
    }

    /**
     * 支付
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function actionPay()
    {
        $params = Yii::$app->request->post();
        $id = $params['v_ip']??'';
        if (!$id){
            return commonApi::message('请选择要购买的会员卡',false);
        }
        $log = new VipLog();
        return $log->buyCard($id,self::$userid);
    }
}